Ruby: Split callable and its body into two AST nodes.#21867
Open
aschackmull wants to merge 5 commits into
Open
Ruby: Split callable and its body into two AST nodes.#21867aschackmull wants to merge 5 commits into
aschackmull wants to merge 5 commits into
Conversation
263bb5c to
8098334
Compare
8098334 to
7dcd2d6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Ruby AST model so callable nodes (methods, blocks, lambdas) no longer double as their statement-sequence bodies, instead introducing an explicit getBody() relationship to improve downstream CFG/dataflow construction.
Changes:
- Introduce
Callable.getBody()and update callable AST classes so bodies are represented as separateBodyStmtnodes. - Update Ruby control-flow and dataflow internals (and several framework/security libraries) to traverse callable bodies via
getBody(). - Regenerate/adjust Ruby library test
.expectedoutputs to reflect the new AST shape (getBody: [StmtSequence] ...nodes).
Show a summary per file
| File | Description |
|---|---|
| ruby/ql/test/library-tests/modules/modules.expected | Updates expected results for module/enclosing-module behavior due to callable body splitting. |
| ruby/ql/test/library-tests/modules/methods.expected | Updates expected results for method-enclosing relationships due to callable body splitting. |
| ruby/ql/test/library-tests/ast/AstDesugar.expected | Updates desugaring AST expectations to include explicit callable bodies. |
| ruby/ql/test/library-tests/ast/Ast.expected | Updates core AST expectations to include explicit callable bodies. |
| ruby/ql/lib/codeql/ruby/security/InsecureDependencyQuery.qll | Uses getBlock().getBody() to find URL parts in git_source blocks. |
| ruby/ql/lib/codeql/ruby/security/ImproperMemoizationQuery.qll | Uses m.getBody() when inspecting the last statement of a method. |
| ruby/ql/lib/codeql/ruby/frameworks/XmlParsing.qll | Traverses parser blocks through .getBlock().getBody() to find relevant calls. |
| ruby/ql/lib/codeql/ruby/frameworks/Slim.qll | Uses .asCallableAstNode().getBody() as the template node source. |
| ruby/ql/lib/codeql/ruby/frameworks/actiondispatch/internal/Routing.qll | Route block wrappers now delegate statements via block.getBody().getAStmt(). |
| ruby/ql/lib/codeql/ruby/experimental/Rbi.qll | Updates RBI modeling to retrieve aliased type and sig-body calls via .getBody(). |
| ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll | Adjusts callable dataflow node hierarchy to avoid assuming a callable is a StmtSequenceNode. |
| ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll | Updates implicit return handling to anchor on c.getBody().getAStmt(). |
| ruby/ql/lib/codeql/ruby/controlflow/internal/Splitting.qll | Updates ensure-splitting logic to use the updated BodyStmtTree API. |
| ruby/ql/lib/codeql/ruby/controlflow/internal/ControlFlowGraphImpl.qll | Refactors CFG scope/tree logic to treat callables and their bodies as distinct nodes. |
| ruby/ql/lib/codeql/ruby/ast/Method.qll | Introduces Callable.getBody() and updates callable subclasses accordingly. |
| ruby/ql/lib/codeql/ruby/ast/internal/Synthesis.qll | Adds synthesis support for synthetic callable bodies (BodyStmtKind). |
| ruby/ql/lib/codeql/ruby/ast/internal/Method.qll | Updates internal callable representations (e.g., brace blocks) to expose getBody(). |
| ruby/ql/lib/codeql/ruby/ast/internal/Expr.qll | Adds internal BodyStmt node classes and updates body-child extraction helpers. |
| ruby/ql/lib/codeql/ruby/ast/internal/AST.qll | Extends cached AST wrappers/synth node kinds to include the new body node types. |
| ruby/ql/lib/codeql/ruby/ast/Expr.qll | Updates BodyStmt.getStmt to allow synthesized children (supporting synthetic bodies). |
| ruby/ql/consistency-queries/CfgConsistency.ql | Updates CFG consistency checks to account for BodyStmt no longer being conflated with callables. |
Copilot's findings
- Files reviewed: 21/21 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Ruby AST has been conflating callable AST nodes and their bodies, which make things awkward for CFG construction. This refactor separates the two and adds a
getBodypredicate to connect them.